package com.hairline.controller;


import com.hairline.bean.*;
import com.hairline.bean.bo.ShipOrderBO;
import com.hairline.bean.vo.*;
import com.hairline.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SuppressWarnings("ALL")
@RestController
public class MarketController {

    @Autowired
    MarketService marketService;

    @RequestMapping("admin/region/list")
    public BaseRespVo regionList() {
        List<Region> regions = marketService.regionList();
        return BaseRespVo.ok(regions);
    }

    @RequestMapping("admin/brand/list")
    public BaseRespVo brandList(Integer page, Integer limit, Integer id, String name, String sort, String order) {
        BrandListVO brands = marketService.brandList(page, limit, id, name, sort, order);
        return BaseRespVo.ok(brands);
    }

    @RequestMapping("admin/brand/create")
    public BaseRespVo brandCreate(@RequestBody Brand brand) {
        int code = marketService.brandCreate(brand);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("添加失败,请检查");
    }

    @RequestMapping("admin/brand/update")
    public BaseRespVo brandUpdate(@RequestBody Brand brand) {
        int code = marketService.brandUpdate(brand);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("更新失败，请检查");
    }

    @RequestMapping("admin/brand/delete")
    public BaseRespVo brandDelete(@RequestBody Brand brand) {
        int code = marketService.brandDelete(brand);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败，请重试");
    }

    @RequestMapping("admin/category/list")
    public BaseRespVo categoryList() {
        List<Category> list = marketService.categoryList();
        return BaseRespVo.ok(list);
    }

    @RequestMapping("admin/category/create")
    public BaseRespVo catagoryCreate(@RequestBody Category category) {
        int code = marketService.categoryCreate(category);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("添加失败，请检查");
    }

    @RequestMapping("admin/category/l1")
    public BaseRespVo catagoryL1() {
        List<CategoryL1VO> categoryL1VO = marketService.categoryL1();
        return BaseRespVo.ok(categoryL1VO);
    }

    @RequestMapping("admin/category/update")
    public BaseRespVo categoryUpdate(@RequestBody Category category) {
        int code = marketService.categoryUpdate(category);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("更新失败，请检查");
    }

    @RequestMapping("admin/category/delete")
    public BaseRespVo categoryDelete(@RequestBody Category category) {
        int code = marketService.categoryDelete(category);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败，请重试");
    }

    @RequestMapping("admin/order/list")
    public BaseRespVo orderList(Integer page, Integer limit, String sort, String order, Short[] orderStatusArray,
                                String orderSn, Integer userId) {
        OrderListVO orderListVO = marketService.orderList(page, limit, sort, order, orderStatusArray, orderSn, userId);
        return BaseRespVo.ok(orderListVO);
    }

    @RequestMapping("admin/order/detail")
    public BaseRespVo orderDetail(Integer id) {
        OrderDetailVO orderDetailVO = marketService.orderDetail(id);
        return BaseRespVo.ok(orderDetailVO);
    }

    @RequestMapping("admin/order/refund")
    public BaseRespVo orderRefund() {
        return BaseRespVo.fail("不接受退款呢亲～");
    }

    @RequestMapping("admin/order/ship")
    public BaseRespVo orderShip(@RequestBody ShipOrderBO shipOrderBO) {
        int code = marketService.orderShip(shipOrderBO);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("发货失败，请检查");
    }

    @RequestMapping("admin/issue/list")
    public BaseRespVo issueList(Integer page, Integer limit, String question, String sort, String order) {
        IssueListVO issueListVO = marketService.issueList(page, limit, question, sort, order);
        return BaseRespVo.ok(issueListVO);
    }

    @RequestMapping("admin/issue/create")
    public BaseRespVo issueCreate(@RequestBody Issue issue) {
        int code = marketService.issueCreate(issue);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("添加失败，请检查");
    }

    @RequestMapping("admin/issue/update")
    public BaseRespVo issueUpdate(@RequestBody Issue issue) {
        int code = marketService.issueUpdate(issue);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("更新失败，请检查");
    }

    @RequestMapping("admin/issue/delete")
    public BaseRespVo issueDelete(@RequestBody Issue issue) {
        int code = marketService.issueDelete(issue);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败，请重试");
    }

    @RequestMapping("admin/keyword/list")
    public BaseRespVo keyworkList(Integer page, Integer limit, String keyword, String url, String sort, String order) {
        KeywordListVO keywordListVO = marketService.keywordList(page, limit, keyword, url, sort, order);
        return BaseRespVo.ok(keywordListVO);
    }

    @RequestMapping("admin/keyword/create")
    public BaseRespVo keywordCreate(@RequestBody Keyword keyword) {
        int code = marketService.keywordCreate(keyword);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("添加失败，请检查");
    }

    @RequestMapping("admin/keyword/update")
    public BaseRespVo keywordUpdate(@RequestBody Keyword keyword) {
        int code = marketService.keywordUpdate(keyword);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("更新失败，请检查");
    }

    @RequestMapping("admin/keyword/delete")
    public BaseRespVo keywordDelete(@RequestBody Keyword keyword) {
        int code = marketService.keywordDelete(keyword);
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败，请检查");
    }
}
